package com.luotao.test.hbase.domain;

import com.luotao.devp.base.test.TesterConcurrent;
import com.luotao.devp.base.utils.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.UUID;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-27
 * Time: 22:48
 */
public class PutExample {
    public static void main(String[] args) throws Exception {
        final Configuration conf = HBaseConfiguration.create();

        //   final
        long cost = TesterConcurrent.runTaskSubClass(300, new TesterConcurrent.ITestable() {
            @Override
            public void execute(long index, long threadid, int loop_count) throws Exception {
              //  System.out.println("loop_count = " + loop_count);
                String s_index = StringUtils.fillZero(String.valueOf(index),5);
                HTable table = new HTable(conf, "testtable2");
//                table.setAutoFlush(false);
                for (int i = 0; i < loop_count; i++) {
                    String s_subIndex = StringUtils.fillZero(String.valueOf(i),5);
                    Put put = new Put(Bytes.toBytes(UUID.randomUUID().toString()));
                    put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), Bytes.toBytes("val"));
                    table.put(put);
                  //  Bytes.toBytes(1) ;
                }
//                table.flushCommits();
            }
        }, 10);
        System.out.println("cost = " + cost);
    }
}
